#include <etcd/Client.hpp>
#include <etcd/KeepAlive.hpp>
#include <etcd/Response.hpp>
#include <thread>

int main(int argc, char* argv[])
{
    std::string etcd_host = "http://127.0.0.1:2379";
    // 1. 创建etcd客户端
    etcd::Client client(etcd_host);

    // 2. 获取租约保活对象————伴随着创建一个租约
    auto keep_clive = client.leasekeepalive(3).get();

    // 3. 从租约中获取id
    auto lease_id = keep_clive->Lease(); 

    // 4. 向etcd中写入键值对
    auto resp1 = client.put("/service/user", "127.0.0.1:8080", lease_id).get();
    if(resp1.is_ok() == false)
    {
        std::cout << "put failed" << resp1.error_message() << std::endl;
        return -1;
    }

    auto resp2 = client.put("/service/friend", "127.0.0.1:9090").get();
    if(resp2.is_ok() == false)
    {
        std::cout << "put failed" << resp2.error_message() << std::endl;
        return -1;
    }

    std::this_thread::sleep_for(std::chrono::seconds(10));
    return 0;
}